

$("#addressFormTwo").hide();
let addressApp=new Vue({
    el:"#addressApp",
    data:{
        addresses:[],
        address:''
    },
    methods:{
        loadAddress:function () {
            axios({
                url:"/portal/address",
                method:'get'
            }).then(function (r) {
                console.log(r.data);
                addressApp.addresses=r.data;
            })

        },
        getAddressToForm:function(address,id){
            $("#addressFormOne").hide();
            $("#addressFormTwo").show();
            console.log(address);
            $("#updateAddressForm textarea").val(address.street);
            // $("#updateAddressForm select[name='provinceName'] option[value='"+address.provinceName+"']").attr("selected","selected");
            // $("#updateAddressForm select[name='cityName'] option[value='"+address.cityName+"']").attr("selected","selected");
            // $("#updateAddressForm select[name='zoneName'] option[value='"+address.zoneName+"']").attr("selected","selected");
            $("#updateAddressForm input[name='postcode']").val(address.postcode);
            $("#updateAddressForm input[name='customerName']").val(address.customerName);
            $("#updateAddressForm input[name='phone']").val(address.phone);
            $("#updateAddressForm input[name='status']").val(address.status);
            $("#updateAddressForm input[name='id']").val(address.id);
            // address.phone=$("#updateAddressForm input[name='phone']").val();
            // address.status
            // let form1=new FormData();
            // //向表单添加需要修改的数据
            // form1.append("address",address);
            // form1.append("cityName",cityName);
            // form1.append("zoneName",zoneName);
            // form1.append("street",street);
            // form1.append("postcode",postcode);
            // form1.append("customerName",customerName);
            // form1.append("phone",phone);
            // form1.append("status",status);
            // axios({
            //     //方式
            //     method:'post',
            //     //通过这个路径去实现
            //     url:'/registerAddress',
            //     //影响表单数据
            //     data:form1
            // })
            //     .then(function(r) {
            //         console.log("|"+r.status+"|"+OK+"|");
            //         if(r.data=="yes"){
            //             console.log("地址添加成功");
            //             console.log(r.data);
            //             addAddressForm.hasError = false;
            //             location.href = '/address.html';
            //         }else{
            //
            //             console.log(r.data);
            //             addAddressForm.hasError = true;
            //             addAddressForm.message = r.data;
            //         }
            //     });

        },
        removeAddress:function (id,index,addresses) {
            axios({
                url:"/portal/address/"+id+"/delete",
                method: "get"
            }).then(function (r) {
                console.log(r.data);
                if(r.data=="删除成功了"){
                    addresses.splice(index,1);
                }else{
                    console.log(r.data)
                }


            })
        },
        // updateAddressFormTwo:function (id,index,addresses) {
        //     let form=new FormData;
        //     form.append("id",id);
        //     form.append("customerName",addresses.customerName);
        //     form.append("provinceName",addresses.provinceName);
        //     form.append("cityName",addresses.cityName);
        //     form.append("zoneName",addresses.zoneName);
        //     form.append("street",addresses.street);
        //     form.append("postcode",addresses.postcode);
        //     form.append("phone",addresses.phone);
        //     form.append("status",addresses.status);
        //     axios({
        //         url:"/portal/address/"+id+"/update",
        //         method:"post",
        //         data:form
        //     }).then(function (response) {
        //         console.log(response.data);
        //
        //     })
        // }
    },
    created:function () {
        this.loadAddress();
    },

})
